<?php

App::uses('AppModel', 'Model');

class Shift extends AppModel
{
    /** Al Agregar/eliminar/actualizar las constantes de los modelos implica ir
     * y actualizar los comentarios en los campos de la tabla asociada a este modelo.
     */
    const STATUS_ENABLED = 1;
    const STATUS_DISABLED = 0;

    /**
     * Buscamos un area por su nombre
     * @param string $name
     * @return array
     */
    public function getByName($name) {
        return $this->find('first', array('conditions' => array(
                        'name' => $name
        )));
    }

    /**
     * Obtenemos los registros para el grid del admin
     * @return type
     */
    public function getEnabled() {
        $filters = array(
            'fields' => array(
                'name as text',
                'id as value'
            ),
            'conditions' => array(
                'status' => self::STATUS_ENABLED
            ),
        );
        $records = $this->find('all', $filters);
        return $this->flatArray($records);
    }
    
    public function getEnabledOrderByCode() {
        $filters = array(
            'fields' => array(
                'name as text',
                'id as value',
            ),
            'conditions' => array(
                'status' => self::STATUS_ENABLED,
            ),
            'order' => array(
                'code ASC'
            ),
        );
        $records = $this->find('all', $filters);
        return $this->flatArray($records);
    }

    public function getShortNameEnabledOrderByCode()
    {
        $filters = array(
            'fields' => array(
                'code as text',
                'id as value',
            ),
            'conditions' => array(
                'status' => self::STATUS_ENABLED,
            ),
            'order' => array(
                'code ASC'
            ),
        );
        $records = $this->find('all', $filters);
        return $this->flatArray($records);
    }

}
